package com.it.you.common.utils;

import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;

public class SpringDynamicCreationUtil {

    public static Object addIntoSpringContext(ApplicationContext ctx, String name, AbstractBeanDefinition beanDefinition){
        DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) ctx.getAutowireCapableBeanFactory();
        defaultListableBeanFactory.registerBeanDefinition(name, beanDefinition);
        return ctx.getBean(name);
    }
}
